package com.sky.controller.user;

import com.sky.constant.MessageConstant;
import com.sky.dto.*;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import com.sky.vo.OrdersPageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Select;
import org.aspectj.weaver.ast.Or;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@Api("C-端 用户订单接口")
@RequestMapping("/user/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @ApiOperation("提交订单")
    @PostMapping("/submit")
    public Result<OrderSubmitVO> submit(@RequestBody OrdersSubmitDTO ordersSubmitDTO){
        log.info("提交订单:{}",ordersSubmitDTO);
        OrderSubmitVO orderSubmitVO = orderService.submit(ordersSubmitDTO);

        return Result.success(orderSubmitVO);
    }

    @ApiOperation("用户支付订单")
    @PutMapping("/payment")
    public Result<OrderPaymentVO> payMent(@RequestBody OrdersPaymentDTO ordersPaymentDTO){
        log.info("用户支付订单:{}",ordersPaymentDTO);
        OrderPaymentVO orderPaymentVO = orderService.payMent(ordersPaymentDTO);

        return Result.success(orderPaymentVO);
    }

    @ApiOperation("请求历史订单")
    @GetMapping("/historyOrders")
    public Result<PageResult> historyOrders(OrdersPageQueryDTO dto){
        log.info("请求历史订单:{}",dto);
        PageResult pageResult = orderService.pageQuery(dto);
        return Result.success(pageResult);
    }

    @ApiOperation("查询订单详情")
    @GetMapping("/orderDetail/{id}")
    public Result<OrderVO> orderDetail(@PathVariable Long id){
        log.info("查看订单详情:{}",id);
        OrderVO orderVO = orderService.details(id);
        return Result.success(orderVO);
    }

    @ApiOperation("取消订单")
    @PutMapping("/cancel/{id}")
    public Result cancel(@PathVariable Long id){
        log.info("用户取消订单:{}",id);
        OrdersCancelDTO dto = new OrdersCancelDTO(id, "用户取消订单");
        orderService.cancel(dto);
        return Result.success();
    }

    @ApiOperation("用户催单")
    @GetMapping("/reminder/{id}")
    public Result reminder(@PathVariable Long id){
        log.info("用户催单:{}",id);
        //催单
        orderService.reminder(id);
        return Result.success();
    }



}
